<?php

class LoginControl extends Control {

    public function index() {
        if (IS_POST) {
            $code = strtoupper(adds_html($_POST['verify']));
            if ($code != $_SESSION['code']) {
                $this->error('验证码不正确！');
            }
            $data = M('admin')->query("SELECT * FROM hd_admin where username='{$_POST['userName']}'");
            if (empty($data) || $data[0]['passwd'] != md5($_POST['psd'])) {
                $this->error('用户名或者密码不正确！');
            }
            $_SESSION['adminname'] = $data[0]['username'];
            $_SESSION['aid'] = $data[0]['aid'];
            $this->success('登陆成功！', __ROOT__);
        }
        $this->display();
    }

    public function code() {
        $code = new Code();
        $code->show();
    }
    public function login_out(){
        session_unset();
        session_destroy();
        $this->success('退出成功！', __ROOT__);
    }

}
